#############################################################################
##
## Document information for TempLaTeX
## 
## Ramon Casero <rcasero@gmail.com>
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
##
###########################################################################

###########################################################################
##
## RULES:
##
## add: add to subversion all .tex, .bib files, and figures (.eps,
##      .fig), Matlab files (.m, .mat) and GNU R files (.R).
##
## clean: remove all compilation files, emacs backup files, main.dvi...
##
## index: create a main.?nd file for each main.?dx file in the directory.
##
## pdf: let us be in directory /path/dir, creates a dir.pdf from main.dvi.
##
## ps: let us be in directory /path/dir, creates a dir.ps from main.dvi.
##
## *.bib: copy bibfiles from common directory to this
## document. E.g. make shapes.bib.
##
###########################################################################


.PHONY: clean index all add

indexfiles := $(wildcard main.?dx)
currentdirname := $(shell pwd)
SVNREP=http://tuscany.robots.ox.ac.uk/svn/MVL

all:
	@echo 
	@echo  RULES:
	@echo 
	@echo  clean: remove all compilation files, emacs backup files, main.dvi...
	@echo 
	@echo  index: create a "main.?nd" file for each "main.?dx" file in the directory
	@echo 
	@echo  ps: let us be in directory /path/dir, creates a dir.ps from main.dvi
	@echo 
	@echo  pdf: let us be in directory /path/dir, creates a dir.pdf from main.dvi
	@echo 

index: $(patsubst main.%dx,main.%nd,$(indexfiles))

main.%nd: main.%dx
	makeindex -o $@ $< 

ps: $(notdir $(currentdirname)).ps

$(notdir $(currentdirname)).ps: main.dvi figures/
	dvips main.dvi && \
	mv main.ps $(notdir $(currentdirname)).ps

pdf: $(notdir $(currentdirname)).pdf

$(notdir $(currentdirname)).pdf: main.dvi figures/
	dvipdf main.dvi $(notdir $(currentdirname)).pdf

%.bib: FORCE
	@if [ -z "$@" ]; then \
	echo No .bib file given; \
	else \
	svn export $(SVNREP)/`whoami`/bibtex/$@; \
	fi

main.dvi:
	@echo Use LaTeX, BibTeX, makeindex, etc. to generate main.dvi before

add:
	svn add *.tex *.bib
	@if [ -d "figures" ]; then \
	svn add figures/*.eps figures/*.fig; \
	fi
	@if [ -d "matlab" ]; then \
	svn add matlab/*.m matlab/*.mat; \
	fi
	@if [ -d "r" ]; then \
	svn add r/*.R; \
	fi

clean:
	rm -rf auto *.aux *.?nd *.?dx *.bbl *.blg main.dvi *.ilg \
*.lof *.log *.lot *.out *.toc *~

FORCE:
